package com.helper.service.impl;

import com.helper.entity.Historyrecord;
import com.helper.dao.HistoryrecordDao;
import com.helper.service.HistoryrecordService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import javax.annotation.Resource;
import java.util.List;


/**
 * (Historyrecord表)服务实现类
 *
 * @author lkc
 */
@Service("historyrecordServiceImpl")
public class HistoryrecordServiceImpl implements HistoryrecordService {
    @Resource
    private HistoryrecordDao historyrecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param historyrecordid 主键
     * @return 实例对象
     */
    @Override
    public Historyrecord selectById(Integer historyrecordid) {
        return this.historyrecordDao.selectById(historyrecordid);
    }

    /**
     * 分页查询
     *
     * @param current 当前页
     * @param size    每一页的条数
     * @return 对象列表
     */
    @Override
    public PageInfo<Historyrecord> selectPage(int current, int size) {
        PageHelper.startPage(current, size);
        List<Historyrecord> dataList = historyrecordDao.selectAll();
        return new PageInfo<>(dataList);
    }

    /**
     * 查询所有
     *
     * @return 实例对象的集合
     */
    @Override
    public List<Historyrecord> selectAll() {
        return this.historyrecordDao.selectAll();
    }

    /**
     * 根据条件查询
     *
     * @return 实例对象的集合
     */
    @Override
    public List<Historyrecord> selectList(Historyrecord historyrecord) {
        return this.historyrecordDao.selectList(historyrecord);
    }

    /**
     * 新增数据
     *
     * @param historyrecord 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public int insert(Historyrecord historyrecord) {
        return this.historyrecordDao.insert(historyrecord);
    }

    /**
     * 批量新增
     *
     * @param historyrecords 实例对象的集合
     * @return 生效的条数
     */
    @Override
    @Transactional
    public int batchInsert(List<Historyrecord> historyrecords) {
        return this.historyrecordDao.batchInsert(historyrecords);
    }

    /**
     * 修改数据
     *
     * @param historyrecord 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public Historyrecord update(Historyrecord historyrecord) {
        this.historyrecordDao.update(historyrecord);
        return this.selectById(historyrecord.getHistoryrecordid());
    }

    /**
     * 通过主键删除数据
     *
     * @param historyrecordid 主键
     * @return 是否成功
     */
    @Override
    @Transactional
    public int deleteById(Integer historyrecordid) {
        return this.historyrecordDao.deleteById(historyrecordid);
    }

    /**
     * 查询总数据数
     *
     * @return 数据总数
     */
    @Override
    public int count() {
        return this.historyrecordDao.count();
    }
}
